package com.yiwei.zxp.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.BoothPacketDetailActivity;
import com.yiwei.zxp.api.model.ComboListModel;
import com.yiwei.zxp.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class BoothPacketAdapter extends ItemAdapter<ComboListModel.DatasBean, BoothPacketAdapter.DefaultHolder> {

    private final int x36;
    private final int x28;

    private Context context;

    public BoothPacketAdapter(Context context) {
        super(context);
        this.context = context;
        x36 = context.getResources().getDimensionPixelSize(R.dimen.x36);
        x28 = context.getResources().getDimensionPixelSize(R.dimen.x28);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_booth_packet, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {

        ComboListModel.DatasBean item = getItem(position);

        holder.txtMoney.setText("￥" + item.money);
        Glide.with(context).load(item.photos).into(holder.imgBg);

        String name = "";
        if (!TextUtils.isEmpty(item.combo_name)) {
            name=item.combo_name;
        }else if(!TextUtils.isEmpty(item.name)){
            name=item.name;
        }
        Spanned txtMoneyContent = Spans.with(context).
                font(name, x36, 0xffffffff).style(Typeface.BOLD).
                font("  (" + item.number + "个商品展示位)", x28, 0xffffffff).
                build();
        holder.txtContent.setText(txtMoneyContent);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BoothPacketDetailActivity.class);
                intent.putExtra("id", item.id);
                context.startActivity(intent);
                ((Activity) context).overridePendingTransition(R.anim.right_enter, R.anim.left_out);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_money)
        TextView txtMoney;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.layout_total)
        FrameLayout layoutTotal;
        @BindView(R.id.img_bg)
        ImageView imgBg;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
